<?php 

if(!defined('ADMIN')){
	exit('Access Denied');
}

$rolelist=array();
?>
<div class="pageContent">
<form method="post" action="index.php?mod=<?=MOD?>&act=<?=ACT?>" class="pageForm required-validate" onsubmit="return validateCallback(this, dialogAjaxDone);">
<input type="hidden" name="id" value="<?=$row['id']?>" />
<input type="hidden" name="sub" value="save" />

<p><label>角色名称：</label><input name="title" type="text" id="title" value="<?=$row['title']?>"/></p>

<div class="pageFormContent" layoutH="70">

<ul class="tree treeFolder treeCheck expand" oncheck="gettreevalue">
<?php foreach($menus as $key=>$row){?>
<li><a ><?=$row['title']?></a>
    <ul>
     <?php foreach($row['children'] as $k=>$v){
        if($role_menu_arr[$v['id']]){
            $rolelist[]=$v['id'];
        }
        ?>
        <li><a tname="ids" tvalue="<?=$v['id']?>" <?php if($role_menu_arr[$v['id']]){?> checked="true" <?php }?>><?=$v['title']?>(模块：<?=$v['mod']?> 行为：<?=$v['act']?>)</a></li>
     <?php }?>
    </ul>
    </li>
<?php }
$jsstr="";
$rlist=implode(",",$rolelist);
if(!empty($rolelist)){
 $jslist=array();
 foreach($rolelist as $k=>$v){
      $jslist[]=$v.":".$v; 
 }
 $jsstr=implode(",",$jslist);
}
?>
</ul>
</div>
<div class="formBar">
			<ul>
				<li><div class="buttonActive"><div class="buttonContent"><button type="submit">保存</button></div></div></li>
				<li>
					<div class="button"><div class="buttonContent"><button type="button" class="close">取消</button></div></div>
				</li>
			</ul>
		</div>
        <input type="hidden" name="resultBox" id="resultBox" value="<?=$rlist?>" />
</form>
</div>
<script type="text/javascript">
var arrayObj ={<?=$jsstr?>};
var a=new Array();
function gettreevalue(){
    
	var json = arguments[0], result="";
	$(json.items).each(function(i){
	    if(this.chk==1){
	       arrayObj[this.value]=this.value;
	    }else{
	       arrayObj[this.value]=0;
	    }
	});
    var j=0;
    for (var i in arrayObj) {
        if(arrayObj[i]>0){
        a[j]=arrayObj[i];
        j++;
        }
    } 
    $("#resultBox").val(a);
}
</script>